sync on
sync rate 60
hide mouse
disable escapekey

dim bombs(74)

set text font "impact"
set text size 15

randomize timer()

load music "game.mid",1
load music "title.mid",2

load image "road.bmp",1
load image "building.bmp",2
load image "sky.bmp",3
load image "target.bmp",4
load image "flash.bmp",6
load image "ackack2.bmp",7,1
load image "city.bmp",8,1
load image "jetfight.bmp",9
load image "jetfigh2.bmp",10
load image "blitter.bmp",11,1
load image "gameover.bmp",12,1
load image "smallcaR.bmp",13
load image "smallcaW.bmp",14
load image "smallcaY.bmp",15

load sound "gun.wav",1
load sound "bang1.wav",2
load sound "bang2.wav",3

load bitmap "ackack2.bmp",1
set current bitmap 1
for i=1 to 599
	get image i+50,i,0,i+1,224
next i
delete bitmap 1

backdrop on
color backdrop 0

loop music 2

paste image 11,20,200
boxin()
for w = 1 to 100
paste image 11,20,200
sync
next w
paste image 11,20,200
boxout()

make matrix 1,20000,200,200,2
prepare matrix texture 1,1,1,1

ob = 0
for mb = 1 to 1000 step 50
ob = ob + 1
y = rnd(4)
ys = (y+1)*25
make object box ob,50,ys,50
position object ob,mb,ys/2,110
texture object ob,2
scale object texture ob,1,(y+1)
ob = ob + 1
make object plain ob,50,50
xrotate object ob,90
position object ob,mb,ys+.05,110
color object ob,0
next mb

make object sphere 41,5000
set object cull 41,0
texture object 41,3
scale object texture 41,4,4

for map = 42 to 52
t = rnd(1)+1
load object "plane"+str$(t)+".x",map
scale object map,600,600,600
`make object box map,50,10,30
hide object map
next map

for mb = 53 to 73
make object box mb,10,2.5,2.5
hide object mb
next mb

for me = 74 to 84
make object plain me,50,50
set object transparency me,1
disable object zdepth me
texture object me,6
hide object me
next me
dim explosions(84)

cx = 1
for mc = 85 to 95
cx = cx + 100
load object "car.x",mc
texture object mc,rnd(2)+13
position object mc,cx,0,rnd(60)
yrotate object mc,rnd(360)
scale object mc,600,600,600
next mc

menu:
open to read 1,"hiscore.ack"
read file 1,hiscore
close file 1
f = 0
stepp=1 : sx=0 : speed=4
do
paste image 8,0,0
for i=1 to 599
paste image i+50,i,sin(sx+i*stepp)*25
next i
inc sx,speed
paste image 4,mousex()-64,mousey()-64,1
position camera 10000,10000,10000
ink rgb(255,255,255),0
center text 320,280,"High Score: "+str$(hiscore)
if mousex() > 290 and mousex() < 350 and mousey() > 320 and mousey() < 330
ink rgb(255,255,0),0
if mouseclick() = 1 then goto game
endif
center text 320,320,"Start"
ink rgb(255,255,255),0
if mousex() > 290 and mousex() < 350 and mousey() > 340 and mousey() < 350
ink rgb(255,255,0),0
if mouseclick() = 1
play sound 1
boxout()
gosub help
endif
endif
center text 320,340,"Help"
ink rgb(255,255,255),0
if mousex() > 290 and mousex() < 350 and mousey() > 360 and mousey() < 370
ink rgb(255,255,0),0
if mouseclick() = 1
play sound 1
boxout()
end
endif
endif
center text 320,360,"Quit"
if f = 0 then boxin():f = 1
sync
cls
loop
boxout()

game:

play sound 1
boxout()

bx = 1
bw = 1
for s = 1 to 40
show object s
bw = bw + 1
if bw > 1 then bx = bx + 50:bw = 0
position object s,bx,object position y(s),object position z(s)
next s
bx = 1
for s = 85 to 95
bx = bx + 100
position object s,bx,object position y(s),object position z(s)
next s
for s = 42 to 52
hide object s
next s
for s = 53 to 73
hide object s
next s
for s = 74 to 84
hide object s
next s

stop music 2

x# = 300
pt = 200
score = 0
shots = 0
hits = 0
dest = 0
tar = rnd(39)+1
bi = 0

loop music 1

do

ink rgb(255,255,0),0

if escapekey() = 1
boxout()
stop music 1
loop music 2
goto menu
endif

if hits > 0 then accuracy = ((hits*100)/shots)

text 5,5,"SCORE: "+str$(score)
text 5,25,"Shots: "+str$(shots)
text 5,40,"Hits: "+str$(hits)
text 5,55,"Accuracy: "+str$(accuracy)+"%"
text 5,75,"Frames Per Second: "+str$(screen fps())
text 5,95,"Buildings Destoryed: "+str$(dest)+"/60"

if dest > 60 then goto gameover

mw = mw - 1
if mouseclick() = 1 and mw < 0
shots = shots + 1
paste image 6,mousex()-64,mousey()-64,1
play sound 1
mw = 10
f = 1
else
f = 0
endif
paste image 4,mousex()-64,mousey()-64,1

yrotate object 41,190

for mb = 1 to 40
if object position x(mb) < x#-350 then position object mb,object position 
x(mb)+1000,object position y(mb),110:show object mb
next mb

for mb = 85 to 95
if object position x(mb) < x#-350 then position object mb,object position 
x(mb)+1000,object position y(mb),object position z(mb):texture object 
mb,rnd(2)+13
next mb

position camera x#,200,-225
position object 41,x#,200,-225

for bo = 74 to 84
if object visible(bo) = 1
scale object bo,explosions(bo),explosions(bo),explosions(bo)
explosions(bo) = explosions(bo) + 10
if explosions(bo) > 200 then hide object bo
zrotate object bo,rnd(360)
position camera camera position x()-2.5+rnd(5),camera position 
y()-2.5+rnd(5),camera position z()-2.5+rnd(5)
endif
next bo

x# = x# + 1.5

pt = pt + 1
if pt > 125 then spawnplane(x#):pt = 0

tp = pick object(mousex(),mousey(),42,52)
if tp > 0 and f = 1
hide object tp
score = score + 1000
hits = hits + 1
pt = 200
spawnexplosion(object position x(tp),object position y(tp),object position 
z(tp))
play sound 2
endif

for mp = 42 to 52
if object visible(mp) = 1

if object position y(mp) > 75 and object position y(mp) < 200
position object mp,object position x(mp)+3.5,object position y(mp),110
endif

if object position y(mp) > 200 and object position y(mp) < 275
position object mp,object position x(mp)-2,object position y(mp),110
endif

if object position x(mp) < x#-310 or object position x(mp) > x#+310 then 
hide object mp

if object position x(mp) > object position x(tar)-25 and object position 
x(mp) < object position x(tar)+25
spawnbomb(object position x(mp),object position y(mp),tar)
tar = rnd(39)+1
endif

for bs = 53 to 73
if object visible(bs) = 1
position object bs,object position x(bs),object position y(bs)-2,object 
position z(bs)
if object position y(bs) < object size y(bombs(bs))
hide object bombs(bs)
if object size z(bombs(bs)) < 5
hide object bombs(bs)-1
else
hide object bombs(bs)+1
endif
spawnexplosion(object position x(bombs(bs)),object position 
y(bombs(bs)),object position z(bombs(bs)))
play sound 3
hide object bs
dest = dest + 1
endif
endif
next bs

endif
next mp

do
if object in screen(tar) = 0 and object visible(tar) = 0
tar = rnd(39)+1
else
exit
endif
loop

if inkey$() = "1" then dest = dest + 1
if inkey$() = "2" then hits = shots

if bi = 0 then boxin():bi = 1

sync

loop

function boxout()
ink 0,0
if image exist(50) then delete image 50
get image 50,0,0,640,480
for x = 0 to 640 step 10
paste image 50,0,0
box 0,0,x,480
sync
next x
endfunction
function boxin()
ink 0,0
if image exist(50) then delete image 50
get image 50,0,0,640,480
for x = 640 to 0 step -10
paste image 50,0,0
box 0,0,x,480
sync
next x
endfunction

function spawnplane(px#)
for cp = 42 to 52
if object visible(cp) = 0 then exit
next cp
p = rnd(1)
if p = 0 then position object cp,px#-300,rnd(75)+125,110:yrotate object 
cp,270
if p = 1 then position object cp,px#+300,rnd(75)+200,110:yrotate object 
cp,90
texture object cp,9+p
show object cp
endfunction

function spawnbomb(px#,py#,ta)
for mb = 53 to 73
if object visible(mb) = 0 then exit
next mb
show object mb
position object mb,px#,py#,110
bombs(mb) = ta
endfunction

function spawnexplosion(ex#,ey#,ez#)
for me = 74 to 84
if object visible(me) = 0 then exit
next me
show object me
position object me,ex#,ey#,ez#
explosions(me) = 0
endfunction

gameover:
f = 0
do
paste image 12,20,100,1
center text 320,200,"Score: "+str$(score)
center text 320,220,"Accuracy Bonus: "+str$(accuracy*1000)
tscore = score+(accuracy*1000)
center text 320,260,"Total Score: "+str$(tscore)
if accuracy > 0 then r$ = "E"
if accuracy > 20 then r$ = "D"
if accuracy > 40 then r$ = "C"
if accuracy > 60 then r$ = "B"
if accuracy > 80 then r$ = "A"
if accuracy = 100 then r$ = "A++++++ - Cheater ^_^"
center text 320,300,"RANK: "+r$
center text 320,340,"Press Space"
if spacekey() = 1 then exit
sync
loop
boxout()
if tscore > hiscore then hiscore = tscore
delete file "hiscore.ack"
open to write 1,"hiscore.ack"
write file 1,hiscore
close file 1
stop music 1
loop music 2
goto menu

help:
do
paste image 8,0,0
ink rgb(255,255,0),0
center text 320,150,"How to Play AckAck II"
center text 320,170,"Use the mouse to aim your missile launcher"
center text 320,185,"Click the left mouse button to fire"
center text 320,200,"Destroy as many aeroplanes as you can before all"
center text 320,215,"60 goverenment buildings are destroyed."
center text 320,235,"Press Space"
if spacekey() = 1 then play sound 1:exit
sync
loop
boxout()
return
